import qs from 'qs'

export function get<T = unknown> (url: string, params?: unknown): Promise<T> {
  let query = ''
  if (params) {
    query = '?' + qs.stringify(params)
  }
  return fetch(url + query).then(res => res.json())
}

export function getClientSts () {
  return get<{
    ExpiredTime: number
    Expiration: string
    Credentials: { Token: string; TmpSecretId: string; TmpSecretKey: string }
    RequestId: string
  }>('https://1302789012-1s32qdku2c.ap-shanghai.tencentscf.com/getClientSts')
}

export function getEmoji () {
  return get<string[]>('https://1302789012-1s32qdku2c.ap-shanghai.tencentscf.com/getEmoji')
}

export function getPhoto () {
  return get<{
    pageNum: number,
    pageSize: number,
    total: number,
    data: string[],
    cachedUnix: number
  }>('http://localhost:9000/getPhoto')
}
